<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 5.4.2">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"xiaoqingming18.github.io","root":"/","images":"/images","scheme":"Muse","darkmode":false,"version":"8.15.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/js/config.js"></script>

    <meta name="description" content="面向对象概述类当谈到Java的类与对象，我们需要理解面向对象编程（OOP）的概念。Java是一种面向对象的编程语言，类是Java中最基本的概念之一，它体现了面向对象编程的核心思想。 类是一种用来描述对象特征和行为的模板或蓝图。可以将类看作是一个抽象的数据类型，它定义了一组属性（也称为成员变量和字段）和方法，用于描述对象的状态和行为。类的实例被称为对象，通过创建对象，我们可以使用类中定义的属性和方法">
<meta property="og:type" content="article">
<meta property="og:title" content="Java：对象与类">
<meta property="og:url" content="http://xiaoqingming18.github.io/2023/06/15/Java%EF%BC%9A%E5%AF%B9%E8%B1%A1%E4%B8%8E%E7%B1%BB/index.html">
<meta property="og:site_name" content="鸣蜩十七">
<meta property="og:description" content="面向对象概述类当谈到Java的类与对象，我们需要理解面向对象编程（OOP）的概念。Java是一种面向对象的编程语言，类是Java中最基本的概念之一，它体现了面向对象编程的核心思想。 类是一种用来描述对象特征和行为的模板或蓝图。可以将类看作是一个抽象的数据类型，它定义了一组属性（也称为成员变量和字段）和方法，用于描述对象的状态和行为。类的实例被称为对象，通过创建对象，我们可以使用类中定义的属性和方法">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-06-15T05:55:34.000Z">
<meta property="article:modified_time" content="2023-06-15T07:39:52.956Z">
<meta property="article:author" content="鸣蜩十七">
<meta property="article:tag" content="-Java基础 -对象与类">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://xiaoqingming18.github.io/2023/06/15/Java%EF%BC%9A%E5%AF%B9%E8%B1%A1%E4%B8%8E%E7%B1%BB/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://xiaoqingming18.github.io/2023/06/15/Java%EF%BC%9A%E5%AF%B9%E8%B1%A1%E4%B8%8E%E7%B1%BB/","path":"2023/06/15/Java：对象与类/","title":"Java：对象与类"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Java：对象与类 | 鸣蜩十七</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>

<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">鸣蜩十七</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">鸣蜩十七是和女朋友谈恋爱的日子</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-schedule"><a href="/schedule/" rel="section"><i class="fa fa-calendar fa-fw"></i>日程表</a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li><li class="menu-item menu-item-commonweal"><a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a></li>
  </ul>
</nav>




</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E6%A6%82%E8%BF%B0"><span class="nav-text">面向对象概述</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%B1%BB"><span class="nav-text">类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AF%B9%E8%B1%A1"><span class="nav-text">对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%B1%BB%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB"><span class="nav-text">类之间的关系</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB"><span class="nav-text">自定义类</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%B1%BB%EF%BC%9F"><span class="nav-text">如何创建一个类？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#this%E5%85%B3%E9%94%AE%E5%AD%97"><span class="nav-text">this关键字</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9E%84%E9%80%A0%E5%99%A8"><span class="nav-text">构造器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%A4%E8%AF%86%E6%9E%84%E9%80%A0%E5%99%A8"><span class="nav-text">认识构造器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%BB%98%E8%AE%A4%E6%9E%84%E9%80%A0%E5%99%A8"><span class="nav-text">默认构造器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9E%84%E9%80%A0%E5%99%A8%E9%87%8D%E8%BD%BD"><span class="nav-text">构造器重载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9E%84%E9%80%A0%E5%99%A8%E9%93%BE"><span class="nav-text">构造器链</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9E%84%E9%80%A0%E5%99%A8%E4%BD%BF%E7%94%A8%E4%BE%8B%E5%AD%90"><span class="nav-text">构造器使用例子</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8var%E5%A3%B0%E6%98%8E%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F"><span class="nav-text">使用var声明局部变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A4%84%E7%90%86%E5%AE%9E%E4%BE%8B%E5%AD%97%E6%AE%B5%E4%B8%BA%E7%A9%BA%E7%9A%84%E6%83%85%E5%86%B5"><span class="nav-text">处理实例字段为空的情况</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%9A%90%E5%BC%8F%E5%8F%82%E6%95%B0%E4%B8%8E%E6%98%BE%E5%BC%8F%E5%8F%82%E6%95%B0"><span class="nav-text">隐式参数与显式参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B0%81%E8%A3%85%E4%B8%8E%E5%B0%81%E8%A3%85%E7%9A%84%E4%BC%98%E7%82%B9"><span class="nav-text">封装与封装的优点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#final%E5%85%B3%E9%94%AE%E5%AD%97"><span class="nav-text">## final关键字</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8final%E5%A3%B0%E6%98%8E%E5%B8%B8%E9%87%8F"><span class="nav-text">使用final声明常量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8final%E5%A3%B0%E6%98%8E%E6%96%B9%E6%B3%95"><span class="nav-text">使用final声明方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8final%E5%A3%B0%E6%98%8E%E7%B1%BB"><span class="nav-text">使用final声明类</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%9D%99%E6%80%81%E5%AD%97%E6%AE%B5%E4%B8%8E%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="nav-text">静态字段与静态方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9D%99%E6%80%81%E5%AD%97%E6%AE%B5"><span class="nav-text">静态字段</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="nav-text">静态方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B7%A5%E5%8E%82%E6%96%B9%E6%B3%95"><span class="nav-text">工厂方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%87%8D%E8%BD%BD"><span class="nav-text">重载</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">鸣蜩十七</p>
  <div class="site-description" itemprop="description">记录我的学习、生活和恋爱日常</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://xiaoqingming18.github.io/2023/06/15/Java%EF%BC%9A%E5%AF%B9%E8%B1%A1%E4%B8%8E%E7%B1%BB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="鸣蜩十七">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="鸣蜩十七">
      <meta itemprop="description" content="记录我的学习、生活和恋爱日常">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Java：对象与类 | 鸣蜩十七">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Java：对象与类
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2023-06-15 13:55:34 / 修改时间：15:39:52" itemprop="dateCreated datePublished" datetime="2023-06-15T13:55:34+08:00">2023-06-15</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%90%8E%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">-后端</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="面向对象概述"><a href="#面向对象概述" class="headerlink" title="面向对象概述"></a>面向对象概述</h1><h2 id="类"><a href="#类" class="headerlink" title="类"></a>类</h2><p>当谈到Java的类与对象，我们需要理解面向对象编程（OOP）的概念。Java是一种面向对象的编程语言，类是Java中最基本的概念之一，它体现了面向对象编程的核心思想。</p>
<p>类是一种用来描述对象特征和行为的模板或蓝图。可以将类看作是一个抽象的数据类型，它定义了一组<strong>属性</strong>（也称为<strong>成员变量</strong>和<strong>字段</strong>）和<strong>方法</strong>，用于描述对象的状态和行为。类的实例被称为对象，通过创建对象，我们可以使用类中定义的属性和方法。</p>
<p><strong>Java中的类，包括用户自己定义的类，都继承子<code>Object</code>类</strong>。</p>
<h2 id="对象"><a href="#对象" class="headerlink" title="对象"></a>对象</h2><p>在Java中，对象是类的实例化结果，它是类的具体化和实体化。对象是内存中的一个实体，具有状态（属性）和行为（方法）。也就是说，<strong>属性用来描述对象的状态，方法用来描述对象的行为</strong>。</p>
<h2 id="类之间的关系"><a href="#类之间的关系" class="headerlink" title="类之间的关系"></a>类之间的关系</h2><p>在Java中，类之间最常见的关系有：</p>
<ul>
<li>依赖（use-a）：依赖关系是一种临时性的使用关系，表示一个类在某个特定的方法中使用了另一个类的对象。依赖关系通常表现为方法参数、局部变量或静态方法的调用。</li>
<li>聚合（has-a）：聚合关系是一种特殊的关联关系，表示整体与部分之间的关系。聚合关系中，整体对象包含部分对象，但部分对象可以存在独立于整体对象的生命周期。聚合关系是一种弱关系，整体对象可以存在没有部分对象的情况。</li>
<li>继承（is-a）：通过继承，一个类（子类）可以继承另一个类（父类）的属性和方法。子类可以扩展或修改继承的属性和方法，同时还可以定义自己的新属性和方法。继承关系用关键字<code>extends</code>表示。</li>
</ul>
<p>在Java程序开发中，应该尽可能减少类之间的<strong>耦合</strong>。即应该尽可能地减少类之间的相互依赖，这样，一个类的改变不会导致另一个类产生BUG。</p>
<h1 id="自定义类"><a href="#自定义类" class="headerlink" title="自定义类"></a>自定义类</h1><h2 id="如何创建一个类？"><a href="#如何创建一个类？" class="headerlink" title="如何创建一个类？"></a>如何创建一个类？</h2><p>类的定义形式如下：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">ClassName</span> {</span><br><span class="line">    field1 <span class="comment">// 属性</span></span><br><span class="line">    field2</span><br><span class="line">    ···</span><br><span class="line">    constructor1 <span class="comment">// 构造器</span></span><br><span class="line">    constructor2</span><br><span class="line">    ···</span><br><span class="line">    method1 <span class="comment">// 方法</span></span><br><span class="line">    method2</span><br><span class="line">    ···</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="this关键字"><a href="#this关键字" class="headerlink" title="this关键字"></a><code>this</code>关键字</h2><p>在Java中，<code>this</code>是一个特殊的关键字，用于引用当前对象的实例。可以用它引用对象的属性，或返回当前对象。</p>
<h2 id="构造器"><a href="#构造器" class="headerlink" title="构造器"></a>构造器</h2><h3 id="认识构造器"><a href="#认识构造器" class="headerlink" title="认识构造器"></a>认识构造器</h3><p>在Java中，<strong>构造器（Constructor）</strong>是类中一种特殊的方法，用于创建对象并初始化对象的<strong>状态（属性）</strong>。构造器具有与类相同的名称，并且没有返回类型（包括void）。每当使用<code>new</code>关键字创建一个对象时，构造器将被调用。</p>
<h3 id="默认构造器"><a href="#默认构造器" class="headerlink" title="默认构造器"></a>默认构造器</h3><p>如果类没有显式定义构造器，Java会提供一个默认构造器。默认构造器没有参数，并且执行默认的初始化操作。但是，<strong>如果类定义了任何构造器（无论是无参数还是有参数的构造器），则默认构造器不会被提供</strong>。</p>
<h3 id="构造器重载"><a href="#构造器重载" class="headerlink" title="构造器重载"></a>构造器重载</h3><p>一个类可以定义多个构造器，只要它们具有不同的参数列表。这被称为构造器重载。通过提供不同的构造器，可以在创建对象时传递不同的参数组合，以满足不同的初始化需求。</p>
<h3 id="构造器链"><a href="#构造器链" class="headerlink" title="构造器链"></a>构造器链</h3><p>通过使用<code>this</code>关键字，在一个构造器中调用另一个重载的构造器，可以创建构造器链。构造器链允许在构造对象时复用通用的初始化逻辑，从而避免代码重复。</p>
<h3 id="构造器使用例子"><a href="#构造器使用例子" class="headerlink" title="构造器使用例子"></a>构造器使用例子</h3><p>下面是一个示例，展示了如何定义和使用构造器：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyClass</span> {</span><br><span class="line">    <span class="keyword">private</span> <span class="type">int</span> myNumber;</span><br><span class="line">    <span class="keyword">private</span> String myString;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 构造器1</span></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">MyClass</span><span class="params">()</span> {</span><br><span class="line">        myNumber = <span class="number">0</span>;</span><br><span class="line">        myString = <span class="string">"Default"</span>;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 构造器2</span></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">MyClass</span><span class="params">(<span class="type">int</span> number, String string)</span> {</span><br><span class="line">        myNumber = number;</span><br><span class="line">        myString = string;</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 构造器3，通过构造器链调用构造器2</span></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">MyClass</span><span class="params">(<span class="type">int</span> number)</span> {</span><br><span class="line">        <span class="built_in">this</span>(number, <span class="string">"Default"</span>);</span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">doSomething</span><span class="params">()</span> {</span><br><span class="line">        <span class="comment">// 方法的实现逻辑</span></span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Main</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">MyClass</span> <span class="variable">object1</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MyClass</span>(); <span class="comment">// 使用构造器1</span></span><br><span class="line">        <span class="type">MyClass</span> <span class="variable">object2</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MyClass</span>(<span class="number">10</span>, <span class="string">"Hello"</span>); <span class="comment">// 使用构造器2</span></span><br><span class="line">        <span class="type">MyClass</span> <span class="variable">object3</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MyClass</span>(<span class="number">20</span>); <span class="comment">// 使用构造器3</span></span><br><span class="line"></span><br><span class="line">        System.out.println(object1.myNumber);</span><br><span class="line">        System.out.println(object2.myString);</span><br><span class="line">        object3.doSomething();</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="使用var声明局部变量"><a href="#使用var声明局部变量" class="headerlink" title="使用var声明局部变量"></a>使用var声明局部变量</h2><p>在Java 10及其以后的版本中，引入了局部变量类型推断的特性，可以使用<code>var</code>关键字来声明局部变量。使用<code>var</code>可以使编码更加简洁，特别是在需要声明复杂类型的变量时。</p>
<p>使用<code>var</code>关键字声明局部变量时，编译器会根据变量的初始化表达式推断其类型。编译器会根据右侧的表达式进行类型推断，并将推断得到的类型应用于变量。</p>
<p>要注意的是，<code>var</code>关键字只能用于声明局部变量，不能用于成员变量、方法参数、方法返回类型以及静态初始化块中的变量。</p>
<p>下面是使用<code>var</code>声明局部变量的示例：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Main</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">var</span> <span class="variable">number</span> <span class="operator">=</span> <span class="number">10</span>; <span class="comment">// 使用var声明整型变量</span></span><br><span class="line">        <span class="type">var</span> <span class="variable">name</span> <span class="operator">=</span> <span class="string">"John"</span>; <span class="comment">// 使用var声明字符串变量</span></span><br><span class="line">        <span class="type">var</span> <span class="variable">myList</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;String&gt;(); <span class="comment">// 使用var声明集合变量</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">var</span> element : myList) {</span><br><span class="line">            <span class="comment">// 遍历集合中的元素</span></span><br><span class="line">        }</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="处理实例字段为空的情况"><a href="#处理实例字段为空的情况" class="headerlink" title="处理实例字段为空的情况"></a>处理实例字段为空的情况</h2><p>有时在实例化一个类时，可能为某个属性赋值为<code>null</code>，但我们又不希望该属性为空，也不希望为其赋值为<code>null</code>，Java针对此情况提供了两种方法。</p>
<p>一个是宽容型方法，当用户调用构造器为一个属性设置为null时，我们希望将<code>null</code>替换为<code>unknown</code>，可以像下面这样实现：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">Employee</span><span class="params">(String name,<span class="type">double</span> salary)</span> {</span><br><span class="line">    <span class="built_in">this</span>.name = Objects.requireNonNullElse(name,<span class="string">"unknown"</span>);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<p>一个是严格型方法，直接拒绝null参数：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">Employee</span><span class="params">(String name,<span class="type">double</span> salary)</span> {</span><br><span class="line">    Objects.requireNonNull(name,<span class="string">"name字段不能为空"</span>);</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<p>这样，当一个人用<code>null</code>为<code>name</code>赋值，就会产生一个<code>NullPointerException</code>异常。</p>
<h2 id="隐式参数与显式参数"><a href="#隐式参数与显式参数" class="headerlink" title="隐式参数与显式参数"></a>隐式参数与显式参数</h2><p>显式参数是通过方法调用中的参数列表明确传递给方法的参数。在方法定义和调用过程中，显式参数的名称和类型是明确的，可以直接访问和使用。</p>
<p>隐式参数是指在方法调用中隐含传递给方法的参数，通常是调用方法的对象本身（或者是当前类的实例）。在方法内部，可以通过使用关键字<code>this</code>来引用隐式参数。</p>
<p>显示参数很普通，来看一个隐式参数的例子：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyClass</span> {</span><br><span class="line">    <span class="keyword">private</span> <span class="type">int</span> number;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setNumber</span><span class="params">(<span class="type">int</span> number)</span> {</span><br><span class="line">        <span class="built_in">this</span>.number = number; <span class="comment">// 隐式参数: this</span></span><br><span class="line">    }</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">MyClass</span> <span class="variable">obj</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">MyClass</span>();</span><br><span class="line">        obj.setNumber(<span class="number">10</span>); <span class="comment">// 隐式参数: obj</span></span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="封装与封装的优点"><a href="#封装与封装的优点" class="headerlink" title="封装与封装的优点"></a>封装与封装的优点</h2><p>在Java中，<strong>封装</strong>是一种面向对象编程的原则和机制，它将数据和操作数据的方法组合在一起，形成一个类，通过限制对类的访问方式来保护数据的安全性。</p>
<p>试想一下，如果将类的属性设置为<code>public</code>，那么任何一个类都可以修改这个类对象的属性，造成数据的破坏。如果将类的属性设置为<code>private</code>，那么这个类的属性就只允许这个类中的方法访问，也就是说，只有这个类实例化的对象才能修改该类属性，简单说就是只允许对象自己修改或访问自己的数据。这就是<strong>封装的思想</strong>。</p>
<p>来看一个例子：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span> {</span><br><span class="line">    <span class="keyword">private</span> String name;<span class="comment">// 将name属性设置为私有的</span></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">Student</span><span class="params">(String name,<span class="type">int</span> age)</span> {</span><br><span class="line">        <span class="built_in">this</span>.name = name;</span><br><span class="line">    }</span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getName</span><span class="params">()</span> {</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">this</span>.name;</span><br><span class="line">    }</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setName</span><span class="params">(String name)</span> {</span><br><span class="line">        <span class="built_in">this</span>.name = name;</span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<p>上面的例子中，<code>Student</code>类的<code>name</code>属性只允许<code>Student</code>对象的<code>getName()</code>和<code>setName()</code>方法来访问和赋值。</p>
<p>一个很重要的点要注意，一个类的<code>getXXX()</code>与<code>setXXX()</code>方法可以访问和设置这个类的所有对象的私有属性。</p>
<h2 id="final关键字"><a href="#final关键字" class="headerlink" title="## final关键字"></a>## <code>final</code>关键字</h2><p><code>final</code>关键字用于表示不可改变的或不可继承的特性。它可以应用于变量、方法和类。</p>
<h3 id="使用final声明常量"><a href="#使用final声明常量" class="headerlink" title="使用final声明常量"></a>使用<code>final</code>声明常量</h3><p>使用<code>final</code>关键字声明的变量是常量，一旦赋予初始值后就无法再修改。它必须在声明时或构造器中进行初始化。</p>
<h3 id="使用final声明方法"><a href="#使用final声明方法" class="headerlink" title="使用final声明方法"></a>使用<code>final</code>声明方法</h3><p>使用<code>final</code>关键字修饰的方法是不可被子类重写的。当在父类中的方法不希望被子类修改时，可以使用<code>final</code>修饰。</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Parent</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title function_">printMessage</span><span class="params">()</span> {</span><br><span class="line">        System.out.println(<span class="string">"This is a final method."</span>);</span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Child</span> <span class="keyword">extends</span> <span class="title class_">Parent</span> {</span><br><span class="line">    <span class="comment">// 无法重写父类的final方法</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h3 id="使用final声明类"><a href="#使用final声明类" class="headerlink" title="使用final声明类"></a>使用<code>final</code>声明类</h3><p>使用<code>final</code>关键字修饰的类是不可被继承的。一旦将类声明为<code>final</code>，其他类无法继承该类。</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">class</span> <span class="title class_">FinalClass</span> {</span><br><span class="line">    <span class="comment">// 类的内容</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 无法从final类继承</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ChildClass</span> <span class="keyword">extends</span> <span class="title class_">FinalClass</span> {</span><br><span class="line">    <span class="comment">// 无法继承final类</span></span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>
<h2 id="静态字段与静态方法"><a href="#静态字段与静态方法" class="headerlink" title="静态字段与静态方法"></a>静态字段与静态方法</h2><p>静态字段和静态方法是与类关联而不是与类的实例关联的成员。它们属于类本身，而不是类的特定实例。也就是说不需要实例化就可以调用类的静态字段与静态方法，以下是关于静态字段和静态方法的介绍。</p>
<h3 id="静态字段"><a href="#静态字段" class="headerlink" title="静态字段"></a>静态字段</h3><p>下面是静态字段的一些说明：</p>
<ul>
<li>静态字段是使用<code>static</code>关键字声明的类级别变量，它被所有类的实例共享。</li>
<li>静态字段在内存中只有一份副本，无论创建多少个类的实例，都共享相同的静态字段。</li>
<li>静态字段可以通过类名直接访问，无需实例化类对象。</li>
<li>静态字段常用于表示与类相关的常量、配置信息或共享状态。</li>
</ul>
<p>来看一个例子：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MyClass</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="type">int</span> count; <span class="comment">// 静态字段</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">increment</span><span class="params">()</span> {</span><br><span class="line">        count++; <span class="comment">// 可以在实例方法中访问静态字段</span></span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 访问静态字段</span></span><br><span class="line">MyClass.count = <span class="number">10</span>;</span><br><span class="line"><span class="type">int</span> <span class="variable">currentCount</span> <span class="operator">=</span> MyClass.count;</span><br></pre></td></tr></tbody></table></figure>
<h3 id="静态方法"><a href="#静态方法" class="headerlink" title="静态方法"></a>静态方法</h3><p>下面是静态方法的一些说明：</p>
<ul>
<li>静态方法是使用<code>static</code>关键字修饰的类级别方法，它不属于类的实例，而是属于类本身。</li>
<li>静态方法可以通过类名直接调用，无需实例化类对象。</li>
<li>静态方法只能直接访问静态字段和调用其他静态方法，无法直接访问实例字段和调用实例方法。</li>
<li>静态方法常用于执行与类相关的操作，例如工具方法、实用方法或创建实例的工厂方法。</li>
</ul>
<p>来看一个例子：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MathUtils</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="type">int</span> <span class="title function_">sum</span><span class="params">(<span class="type">int</span> a, <span class="type">int</span> b)</span> {</span><br><span class="line">        <span class="keyword">return</span> a + b;</span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// 调用静态方法</span></span><br><span class="line"><span class="type">int</span> <span class="variable">result</span> <span class="operator">=</span> MathUtils.sum(<span class="number">3</span>, <span class="number">5</span>);</span><br></pre></td></tr></tbody></table></figure>
<h2 id="工厂方法"><a href="#工厂方法" class="headerlink" title="工厂方法"></a>工厂方法</h2><p><strong>==暂时不会，等补充==</strong></p>
<h2 id="重载"><a href="#重载" class="headerlink" title="重载"></a>重载</h2><p><strong>重载</strong>是指在同一个类中可以定义多个具有相同名称但参数列表不同的方法。重载允许使用相同的方法名来执行不同的操作，根据不同的参数类型、参数个数或参数顺序来区分方法。</p>
<p>以下是方法重载的特点和规则：</p>
<ol>
<li>方法签名：方法的签名由方法名和参数列表组成。参数列表包括参数的类型、顺序和个数。方法的返回类型不是方法签名的一部分，因此不能仅仅通过返回类型的不同来重载方法。</li>
<li>参数列表的不同：方法重载要求参数列表不同，可以通过参数的类型、个数和顺序来区分方法。即使返回类型相同，只有参数列表不同的方法也可以进行重载。</li>
<li>访问修饰符和异常：重载的方法可以具有不同的访问修饰符（public、private、protected等）和不同的异常声明，但这些因素不会影响方法的重载。</li>
<li>返回类型：方法的返回类型不是重载方法的条件。如果仅返回类型不同，而其他方面相同（如参数列表），则会导致编译错误。</li>
<li>调用重载方法：在调用重载方法时，编译器会根据参数列表的匹配程度选择合适的方法。如果有多个方法都符合参数列表，编译器会根据最佳匹配原则选择最具体的方法。</li>
</ol>
<p>下面是一个方法重载的例子：</p>
<figure class="highlight java"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Calculator</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">add</span><span class="params">(<span class="type">int</span> a, <span class="type">int</span> b)</span> {</span><br><span class="line">        <span class="keyword">return</span> a + b;</span><br><span class="line">    }</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">public</span> <span class="type">double</span> <span class="title function_">add</span><span class="params">(<span class="type">double</span> a, <span class="type">double</span> b)</span> {</span><br><span class="line">        <span class="keyword">return</span> a + b;</span><br><span class="line">    }</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">add</span><span class="params">(<span class="type">int</span> a, <span class="type">int</span> b, <span class="type">int</span> c)</span> {</span><br><span class="line">        <span class="keyword">return</span> a + b + c;</span><br><span class="line">    }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Main</span> {</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> {</span><br><span class="line">        <span class="type">Calculator</span> <span class="variable">calculator</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Calculator</span>();</span><br><span class="line">        <span class="type">int</span> <span class="variable">result1</span> <span class="operator">=</span> calculator.add(<span class="number">2</span>, <span class="number">3</span>); <span class="comment">// 调用add(int a, int b)</span></span><br><span class="line">        <span class="type">double</span> <span class="variable">result2</span> <span class="operator">=</span> calculator.add(<span class="number">2.5</span>, <span class="number">3.7</span>); <span class="comment">// 调用add(double a, double b)</span></span><br><span class="line">        <span class="type">int</span> <span class="variable">result3</span> <span class="operator">=</span> calculator.add(<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>); <span class="comment">// 调用add(int a, int b, int c)</span></span><br><span class="line">    }</span><br><span class="line">}</span><br></pre></td></tr></tbody></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Java%E5%9F%BA%E7%A1%80-%E5%AF%B9%E8%B1%A1%E4%B8%8E%E7%B1%BB/" rel="tag"># -Java基础 -对象与类</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2023/06/13/CPU/" rel="prev" title="">
                  <i class="fa fa-chevron-left"></i> 
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2023/06/15/Java%EF%BC%9A%E7%BB%A7%E6%89%BF/" rel="next" title="Java：继承">
                  Java：继承 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">鸣蜩十七</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/muse/" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  




  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>



</body>
</html>
